<?php

	class SendSMS_WebSMS extends SendSMS {

		const LOGIN    = 'login';
		const PASSWORD = 'password';

		public final function realSend($phone, $text, $sender = null) {

			$login    = self::LOGIN;
			$password = self::PASSWORD;
			$sender   = is_null($sender) ? Config_SMS::SENDER : $sender;

			$phone = str_replace(array(' ', '-', '(', ')', '+'), '', $phone);
			if ($phone[0] == '7') {
				$phone[0] = '8';
			}
			if (strlen($phone) != 11) {
				return false;
			}

			$text = iconv('UTF-8','WINDOWS-1251//TRANSLIT', $text);

			$u  = 'http://www.websms.ru/http_in5.asp';
			$ch = curl_init();

			$post = 'Http_username=' . urlencode($login) . '&Http_password=' . urlencode($password) . '&Phone_list=' . $phone . '&Message=' . urlencode($text);
			if ($sender) $post .= '&fromPhone=' . urlencode($sender);

			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
			curl_setopt($ch, CURLOPT_URL, $u);
			$u = trim(curl_exec($ch));
			curl_close($ch);

			preg_match("/message_id\s*=\s*[0-9]+/i", $u, $arr_id);
			$id = preg_replace("/message_id\s*=\s*/i", "", @strval($arr_id[0]));
			return $id;
		}
	}

